#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>

 void sig(){
        puts("TIME IS OUT!");  //和printf功能相似也可以作为输出
        exit(0);
    }

int main(int argc,char *argv[]){
    struct sigaction *act 
 = (struct sigaction *)malloc(sizeof(struct sigaction) * 1); //结构体指针不能指向不完整结构体
    int ret = -1;
    int second;
if(2>argc) exit(-1);
    act->sa_handler = sig;
    second = atoi(argv[1]); //将arg[1]转化成整型
   sigaction(SIGALRM,act,NULL);
   ret = alarm(second);
   printf("倒计时：%d 秒\n",second);
   while(1);  //死循环凑够3S
   return 0;
}